﻿@import "color";

// Fade out other elements when the spinner is showing.
.is-showingSpinner {
    > .spinner--unclickable,
    > .spinner--unclickable * {
        pointer-events: none;
    }

    > .spinner--faded {
        opacity: .1;
    }

    > .spinner--faded--light {
        opacity: .3;
    }

    spinner {
        display: inline-block;
    }
}

spinner {
    position: relative;
    display: none;
    width: 28px;
    height: 28px;
    // Fix the fact that inline elements have implicit spacing
    font-size: 0;
}

.spinner-container {
    width: 100%;
    height: 100%;
    -webkit-animation: container-rotate 1568ms linear infinite;
}

@-webkit-keyframes container-rotate {
    to {
        transform: rotate(360deg);
    }
}

.spinner-layer {
    position: absolute;
    width: 100%;
    height: 100%;
    opacity: 0;
}

.spinner-layer--blue {
    border-color: @blue--500;
    -webkit-animation: fill-unfill-rotate 5332ms cubic-bezier(0.4, 0.0, 0.2, 1) infinite both, blue-fade-in-out 5332ms cubic-bezier(0.4, 0.0, 0.2, 1) infinite both;
}

.spinner-layer--red {
    border-color: @red--500;
    -webkit-animation: fill-unfill-rotate 5332ms cubic-bezier(0.4, 0.0, 0.2, 1) infinite both, red-fade-in-out 5332ms cubic-bezier(0.4, 0.0, 0.2, 1) infinite both;
}

.spinner-layer--yellow {
    border-color: @yellow--500;
    -webkit-animation: fill-unfill-rotate 5332ms cubic-bezier(0.4, 0.0, 0.2, 1) infinite both, yellow-fade-in-out 5332ms cubic-bezier(0.4, 0.0, 0.2, 1) infinite both;
}

.spinner-layer--green {
    border-color: @green--500;
    -webkit-animation: fill-unfill-rotate 5332ms cubic-bezier(0.4, 0.0, 0.2, 1) infinite both, green-fade-in-out 5332ms cubic-bezier(0.4, 0.0, 0.2, 1) infinite both;
}

@-webkit-keyframes fill-unfill-rotate {
    12.5% {
        transform: rotate(135deg);
    }

    25% {
        transform: rotate(270deg);
    }

    37.5% {
        transform: rotate(405deg);
    }

    50% {
        transform: rotate(540deg);
    }

    62.5% {
        transform: rotate(675deg);
    }

    75% {
        transform: rotate(810deg);
    }

    87.5% {
        transform: rotate(945deg);
    }

    to {
        transform: rotate(1080deg);
    }
}

@-webkit-keyframes blue-fade-in-out {
    from {
        opacity: 1;
    }

    25% {
        opacity: 1;
    }

    26% {
        opacity: 0;
    }

    89% {
        opacity: 0;
    }

    90% {
        opacity: 1;
    }

    100% {
        opacity: 1;
    }
}

@-webkit-keyframes red-fade-in-out {
    from {
        opacity: 0;
    }

    15% {
        opacity: 0;
    }

    25% {
        opacity: 1;
    }

    50% {
        opacity: 1;
    }

    51% {
        opacity: 0;
    }
}

@-webkit-keyframes yellow-fade-in-out {
    from {
        opacity: 0;
    }

    40% {
        opacity: 0;
    }

    50% {
        opacity: 1;
    }

    75% {
        opacity: 1;
    }

    76% {
        opacity: 0;
    }
}

@-webkit-keyframes green-fade-in-out {
    from {
        opacity: 0;
    }

    65% {
        opacity: 0;
    }

    75% {
        opacity: 1;
    }

    90% {
        opacity: 1;
    }

    100% {
        opacity: 0;
    }
}

.spinner-clipper {
    position: relative;
    display: inline-block;
    width: 50%;
    height: 100%;
    overflow: hidden;
    border-color: inherit;
}

.spinner-circle {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    width: 200%;
    height: 100%;
    border-color: inherit;
    border-bottom-color: transparent !important;
    border-style: solid;
    border-width: 2px;
    border-radius: 50%;
    -webkit-animation: none;
}

.spinner-clipper--left .spinner-circle {
    border-right-color: transparent !important;
    transform: rotate(129deg);
    -webkit-animation: left-spin 1333ms cubic-bezier(0.4, 0.0, 0.2, 1) infinite both;
}

.spinner-clipper--right .spinner-circle {
    left: -100%;
    border-left-color: transparent !important;
    transform: rotate(-129deg);
    -webkit-animation: right-spin 1333ms cubic-bezier(0.4, 0.0, 0.2, 1) infinite both;
}

@-webkit-keyframes left-spin {
    from {
        transform: rotate(130deg);
    }

    50% {
        transform: rotate(-5deg);
    }

    to {
        transform: rotate(130deg);
    }
}

@-webkit-keyframes right-spin {
    from {
        transform: rotate(-130deg);
    }

    50% {
        transform: rotate(5deg);
    }

    to {
        transform: rotate(-130deg);
    }
}

/**
 * Patch the gap that appear between the two adjacent div.spinner-clipper while the
 * spinner is rotating
 */
.spinner--patch{
    position: absolute;
    top: 0;
    left: 45%;
    width: 10%;
    height: 100%;
    overflow: hidden;
    border-color: inherit;
}

.spinner--patch .spinner-circle {
    left: -450%;
    width: 1000%;
}